package com.cainaer.orders.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cainaer.orders.domain.OrderItem;
import com.cainaer.orders.mapper.OrderItemMapper;
import com.cainaer.orders.service.IOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 订单商品信息表 服务实现类
 * </p>
 *
 * @author Tina
 * @since 2020-09-11
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;

    /**
     * 新增订单商品信息
     *
     * @param orderItem
     * @return
     */
    @Override
    public Integer insertOrderItem(OrderItem orderItem) {
        return orderItemMapper.insert(orderItem);
    }

    /**
     * 编辑订单商品信息
     *
     * @param orderItem
     * @return
     */
    @Override
    public Integer editOrderItem(OrderItem orderItem) {
        return orderItemMapper.updateById(orderItem);
    }

    @Override
    public List<Long> selectOrderItemProductIdListsByShopId(Long shopId) {
        return orderItemMapper.selectOrderItemProductIdListsByShopId(shopId);
    }

    /**
     * 查询订单商品信息
     *
     * @param orderItem
     * @return
     */
    @Override
    public List<OrderItem> selectOrderItem(OrderItem orderItem) {
        QueryWrapper<OrderItem> queryWrapper = new QueryWrapper<>();
        if (orderItem.getShopId()!=null&&orderItem.getShopId()!=0){
            queryWrapper.eq("shop_id",orderItem.getShopId());
        }
        return orderItemMapper.selectList(queryWrapper);
    }
}
